package org.tech4j.edi.common.enums;

import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2022-07-05 10:32
 **/
public enum RetryStatusEnum {

    /**
     * edi状态
     */
    RETRY_INIT(0, "初始状态", "状态一直为初始状态中"),
    RETRY_ING(1, "重试中", "状态一直为重试中"),
    RETRY_SUCCESS(2, "成功", ""),
    RETRY_FAIL(3, "失败", ""),
    RETRY_STOP(4, "达到最大重试次数", "失败重试次数达到上限"),
    RETRY_CLOSE(5, "关闭", ""),
    ;

    private final int type;

    private final String desc;

    private final String alarmDesc;

    /**
     * 获取正常状态集合
     * @return
     */
    public static List<Integer> getNormalStatusList() {
        return new ArrayList<Integer>() {
            {
                add(RETRY_INIT.getType());
                add(RETRY_ING.getType());
                add(RETRY_SUCCESS.getType());
                add(RETRY_FAIL.getType());
            }
        };
    }

    public static List<RetryStatusEnum> getAlarmStatusList() {
        return Lists.newArrayList(
                RETRY_INIT,
                RETRY_FAIL,
                RETRY_STOP
        );
    }

    RetryStatusEnum(int type, String desc, String alarmDesc) {
        this.type = type;
        this.desc = desc;
        this.alarmDesc = alarmDesc;
    }

    public int getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public String getAlarmDesc() {
        return alarmDesc;
    }

    public boolean isSuccess() {
        return Objects.equals(this, RETRY_SUCCESS);
    }

    public boolean canRetry() {
        return RETRY_ING != this;
    }

    public boolean isFailed() {
        return !isSuccess();
    }

    public boolean isOver() {
        return !isSuccess();
    }
}
